/*
 * Copyright (C) 2017-2020 Alibaba Group Holding Limited
 */

/* eip76_types.h
 *
 * EIP76 Driver Library Public Interface: type definitions
 */


#ifndef INCLUDE_GUARD_EIP76_TYPES_H
#define INCLUDE_GUARD_EIP76_TYPES_H

/*----------------------------------------------------------------------------
 * This module uses (requires) the following interface(s):
 */

// Driver Framework Basic Definitions API
#include "basic_defs.h"             // uint32_t, BIT_*


/*----------------------------------------------------------------------------
 * Definitions and macros
 */

#define EIP76_IOAREA_REQUIRED_SIZE              (7 * sizeof(void*))

#define EIP76_RANDOM128_WORD32_COUNT            4

/*----------------------------------------------------------------------------
 * EIP76_Status_t
 *
 * Status (error) code type returned by these API functions
 * See each function "Return value" for details.
 *
 * EIP76_NO_ERROR : successful completion of the call.
 * EIP76_UNSUPPORTED_FEATURE_ERROR : not supported by the device.
 * EIP76_ARGUMENT_ERROR :  invalid argument for a function parameter.
 * EIP76_BUSY_RETRY_LATER : Device is busy.
 * EIP76_PROCESSING : Device is processing data
 * EIP76_ILLEGAL_IN_STATE : illegal state transition
 * EIP76_MONOBIT_FAIL : Monobit known-answer test failed
 * EIP76_REPCNT_FAIL : Repetition count known-answer test failed
 * EIP76_ADPRO_FAIL : Adaptive known-answer test failed
 * EIP76_SHA_FAIL : SHA Conditioning Function known-answer test failed
 */
typedef enum
{
    EIP76_NO_ERROR = 0,
    EIP76_UNSUPPORTED_FEATURE_ERROR,
    EIP76_ARGUMENT_ERROR,
    EIP76_BUSY_RETRY_LATER,
    EIP76_PROCESSING,
    EIP76_ILLEGAL_IN_STATE,
    EIP76_RANDOM_READ_ERROR,
    EIP76_MONOBIT_FAIL,
    EIP76_REPCNT_FAIL,
    EIP76_ADPRO_FAIL,
    EIP76_SHA_FAIL
} EIP76_Status_t;

/*----------------------------------------------------------------------------
 * EIP76_Events_t
 *
 * Bit-mask for the events that can be generated by the TRNG device
 */
typedef enum
{
    // Random data ready event
    EIP76_DATA_READY_EVENT       = BIT_0,

    // Fatal error events
    EIP76_SHUTDOWN_OFLO_EVENT    = BIT_1, // can be configured as alarm event
    EIP76_STUCK_OUT_EVENT        = BIT_2,
    EIP76_NOISE_FAIL_EVENT       = BIT_3,

    // Alarm events
    EIP76_RUN_FAIL_EVENT         = BIT_4,
    EIP76_LONG_RUN_FAIL_EVENT    = BIT_5,
    EIP76_POKER_FAIL_EVENT       = BIT_6,
    EIP76_MONOBIT_FAIL_EVENT     = BIT_7,
    EIP76_STUCK_NRBG_EVENT       = BIT_9,
    EIP76_REPCNT_FAIL_EVENT      = BIT_13,
    EIP76_APROP_FAIL_EVENT       = BIT_14
} EIP76_Events_t;

// Bit-mask for the events defined by EIP76_Events_t
typedef uint32_t EIP76_EventStatus_t;

// 128-bit random number data structure
typedef struct
{
    // word[0] - Least significant word
    // word[1] - Second word
    // word[2] - Third word
    // word[3] - Most significant word
    uint32_t word[EIP76_RANDOM128_WORD32_COUNT];
} EIP76_Random128_t;

// place holder for device specific internal data
typedef struct
{
    uint32_t placeholder[EIP76_IOAREA_REQUIRED_SIZE];
} EIP76_IOArea_t;

// Capabilities structure for EIP-76
typedef struct
{
    // 0 - no Post Processor,
    // 5 - SP 800-90 AES-256 Post Processor
    // 7 - SP 800-90 BC_DF
    uint8_t PostProcessorType;

    // Number of FRO's
    uint8_t NofFRO;

    // 0 - no buffer
    // 1 - reserved
    // 2 ... 7 - number of address bits used to address 128-bit blocks
    uint8_t BufferSize;

    // AIS testing enabled (PRM).
    uint8_t AIS31Testing;

    // Conditioning function option
    uint8_t ConditioningFunction;

    // BC_DF Conditioning function option
    uint8_t BcdfFunction;

    // AutoDetune option
    uint8_t AutoDetune;

    // FIPS SP80090B draft-2 support
    // Used in HW2.3 and later
    uint8_t Fips90B2;

    // Updated FRO sampling method
    // Used in HW3.0 and later
    uint8_t ImprovedFRO;

    // The basic EIP number.
    uint8_t EipNumber;

    // The complement of the basic EIP number.
    uint8_t ComplmtEipNumber;

    // Hardware Patch Level.
    uint8_t HWPatchLevel;

    // Minor Hardware revision.
    uint8_t MinHWRevision;

    // Major Hardware revision.
    uint8_t MajHWRevision;

} EIP76_Capabilities_t;

#endif /* INCLUDE_GUARD_EIP76_TYPES_H */


/* end of file eip76_types.h */
